# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

# Replication code for "Mirroring of the Dragon: How Values and Political Values Affect Perception of China’s National Image? Evidence from the Asian Barometer Survey"

# Author: Zongyi Huo (huozy22@mails.tsinghua.edu.cn)

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# LIBRARIES AND DATA IMPORT ----------------------------------------------------
# ______________________________________________________________________________

rm(list = ls())

library(pacman)

p_load(bruceR,
       dotwhisker,
       estimatr,
       gt,
       ggsci,
       gridExtra,
       kableExtra,
       modelsummary,
       rio,
       tidyverse)

# Import data
data1 <- import("02_data.sav")

## Delete all data from China mainland, Hong Kong, Macau, and Taiwan 
data2 <- subset(data1, country != '2')
data2 <- subset(data2, country != '4')
data2 <- subset(data2, country != '7')

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# SET COLOR -----------------------------------------------------------
# ______________________________________________________________________________

zhucao <- rgb(166, 064, 054, max=255)
qingquetoudai <- rgb(053, 078, 107, max=255)
fuguang <- rgb(240, 194, 162, max=255)
tushoulan <- rgb(065, 130, 164,max=255)

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# SUMMARY STATISTICS -----------------------------------------------------------
# ______________________________________________________________________________

# Table A2
MinMax <- function(x) paste0('[', min(x, na.rm = TRUE), ', ', max(x, na.rm = TRUE), ']')

datasummary((`Affective dimension` = cni) + 
                (`Cognitive dimension` = cni2) +
                (`Self enhancement-self transcendence values` = v1) + 
                (`Openness to change-conservation values` = v2) + 
                (`Democracy political values` = pv1) + 
                (`Freedom political values` = pv2) + 
                (`Equality political values` = pv3) + 
                (`National interest perception at Asian level` = asian) + 
                (`National interest perception at global level` = world) + 
                (`Social media use` = sm) + 
                (`Internet use` = internet) + 
                (Gender = gender) + 
                (Age = age) + 
                (`Education level` = edu) + 
                (`Income level` = income) ~ 
                (Mean = Mean) + 
                (S.D. = SD) + 
                (`Min-Max`= MinMax) +
                (Number = Ncol), 
                data = data2,
                title = 'Summary statistics',
                output = 'kableExtra')

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# ESTIMATE MODELS --------------------------------------------------------------
# ______________________________________________________________________________
model1 <- lmer(cni ~ v1 + v2 + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model2 <- lmer(cni~ pv1 + pv2 + pv3 + sm + internet  + gender + age + edu +income + (1 | country), data = data2)

model3 <- lmer(cni ~ v1 + v2 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model4 <- lmer(cni ~ pv1 + pv2 + pv3 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model5 <- lmer(cni ~ asian + world + sm + internet + gender + age + edu +income + + (1 | country), data = data2)

model6 <- lmer(cni2 ~ v1 + v2 + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model7 <- lmer(cni2 ~ pv1 + pv2 + pv3 + sm + internet  + gender + age + edu +income + (1 | country), data = data2)

model8 <- lmer(cni2 ~ v1 + v2 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model9 <- lmer(cni2 ~ pv1 + pv2 + pv3 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model10 <- lmer(cni2 ~ asian + world + sm + internet + gender + age + edu +income + + (1 | country), data = data2)

# Use the inverse-hyperbolic-sine transformation method
calculate_hat_x <- function(x) {
    log(x + sqrt(x^2 + 1))
}

data2$cniihs <- calculate_hat_x(data2$cni)

data2$cni2ihs <- calculate_hat_x(data2$cni2)

model11 <- lmer(cniihs ~ v1 + v2 + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model12 <- lmer(cniihs ~ pv1 + pv2 + pv3 + sm + internet  + gender + age + edu +income + (1 | country), data = data2)

model13 <- lmer(cniihs ~ v1 + v2 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model14 <- lmer(cniihs ~ pv1 + pv2 + pv3 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model15 <- lmer(cniihs ~ asian + world + sm + internet + gender + age + edu +income + + (1 | country), data = data2)

model16 <- lmer(cni2ihs ~ v1 + v2 + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model17 <- lmer(cni2ihs ~ pv1 + pv2 + pv3 + sm + internet  + gender + age + edu +income + (1 | country), data = data2)

model18 <- lmer(cni2ihs ~ v1 + v2 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model19 <- lmer(cni2ihs ~ pv1 + pv2 + pv3 + asian + world + sm + internet + gender + age + edu +income + (1 | country), data = data2)

model20 <- lmer(cni2ihs ~ asian + world + sm + internet + gender + age + edu +income + + (1 | country), data = data2)

# Calculate the mediating effect
PROCESS(data2, 
        y="cni", 
        x="v1",
        meds=c("pv1", "pv2", "pv3"), 
        covs=c("sm", "internet", "gender", "age", "edu", "income"), 
        clusters="country", 
        ci="boot", 
        nsim=5000, 
        seed=1)

PROCESS(data2, 
        y="cni", 
        x="v2",
        meds=c("pv1", "pv2", "pv3"), 
        covs=c("sm", "internet", "gender", "age", "edu", "income"), 
        clusters="country", 
        ci="boot", 
        nsim=5000, 
        seed=2)

PROCESS(data2, 
        y="cni2", 
        x="v1",
        meds=c("pv1", "pv2", "pv3"), 
        covs=c("sm", "internet", "gender", "age", "edu", "income"), 
        clusters="country", 
        ci="boot", 
        nsim=5000, 
        seed=3)

PROCESS(data2, 
        y="cni2", 
        x="v2",
        meds=c("pv1", "pv2", "pv3"), 
        covs=c("sm", "internet", "gender", "age", "edu", "income"), 
        clusters="country", 
        ci="boot", 
        nsim=5000, 
        seed=4)

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# CREATE TABLES ---------------------------------------------------------------
# ______________________________________________________________________________

# Table A1
table1data <- data.frame(
    Country = c('Japan', 'South Korea', 'Mongolia', 'Philippines', 'Thailand', 'Indonesia',
                'Singapore', 'Vietnam', 'Malaysia', 'Myanmar', 'Australia', 'India'),
    Sample = c(1045, 1268, 1284, 1200, 1200, 1540,
               1002, 1200, 1237, 1627, 1630, 5318))

table1data1 <- data.frame(
    Country = table1data$Country[1:(nrow(table1data)/2)],
    Sample = table1data$Sample[1:(nrow(table1data)/2)],
    Country = table1data$Country[(nrow(table1data)/2 + 1):nrow(table1data)],
    Sample = table1data$Sample[(nrow(table1data)/2 + 1):nrow(table1data)]
)

colnames(table1data1) <- c('Country', 'Sample', 'Country', 'Sample')

knitr::kable (table1data1, 
              align = 'c',
              caption = 'Countries and samples',
              col.names = gsub('[.]', ' ', names(table1data1))) |> 
    kableExtra::kable_styling(latex_options = 'hold_position', full_width = FALSE)

# Table A3
models1 <- list(
    'Values' = model6,
    'Political values' = model7,
    'Values' = model8,
    'Political values' = model9,
    'National interest perception' = model10
)

cm <- c(
    'v1' = 'Self enhancement-self transcendence values',
    'v2' = 'Openness to change-conservation values',
    'pv1' = 'Democracy',
    'pv2' = 'Freedom',
    'pv3' = 'Equality',
    'asian' = 'Asian',
    'world' = 'Global',
    'sm' = 'Social media',
    'internet' = 'Internet',
    'gender' = 'Gender',
    'age' = 'Age',
    'edu' = 'Education',
    'income' = 'Income'
)

modelsummary(models1,
             title = 'Regression results (Dependent variable is cognitive dimension)',
             output = 'gt',
             voc = 'robust',
             statistic = '({p.value})',
             stars = c('***' = .01, '**' = .05, '*' = .1),
             coef_omit = 'Intercept',
             coef_map = cm,
             gof_map = c('nobs', 'r2.marginal', 'r2.conditional', 'aic','bic','rmse'),
             notes = 'Note: p-Values computed using robust standard errors are in parentheses.'
) |>
    opt_stylize() |> 
    tab_row_group(
        label = md('*Control variables*'),
        rows = 15:26
    ) |> 
    tab_row_group(
        label = md('*Explanatory variables*'),
        rows = 1:14
    ) |> 
    tab_options(table.font.size = px(10),
                data_row.padding = px(2),
                table.width = pct(103) ) |> 
    opt_vertical_padding(scale = 0.25) |> 
    opt_horizontal_padding(scale = 0.4)


# Table A4
models2 <- list(
    'Values' = model1,
    'Political values' = model2,
    'Values' = model3,
    'Political values' = model4,
    'National interest perception' = model5
)

modelsummary(models2,
             title = 'Regression results (Dependent variable is affective dimension)',
             output = 'gt',
             voc = 'robust',
             statistic = '({p.value})',
             stars = c('***' = .01, '**' = .05, '*' = .1),
             coef_omit = 'Intercept',
             coef_map = cm,
             gof_map = c('nobs', 'r2.marginal', 'r2.conditional', 'aic', 'bic', 'rmse'),
             notes = 'Note: p-Values computed using robust standard errors are in parentheses.'
) |>
    opt_stylize() |> 
    tab_row_group(
        label = md('*Control variables*'),
        rows = 15:26
    ) |> 
    tab_row_group(
        label = md('*Explanatory variables*'),
        rows = 1:14
    ) |> 
    tab_options(table.font.size = px(10),
                data_row.padding = px(2),
                table.width = pct(103) ) |> 
    opt_vertical_padding(scale = 0.25) |> 
    opt_horizontal_padding(scale = 0.4)

# Table A5 (See the result in # Calculate the mediating effect)
table5data <- data.frame(
    Explanatoryvariables = c('SS', 'SS', 'SS', 'OC', 'OC', 'OC', 'SS', 'SS', 'SS', 'OC', 'OC', 'OC'),
    Dependentvariables = c('Cognitive', 'Cognitive', 'Cognitive', 'Cognitive', 'Cognitive', 'Cognitive',
                           'Affective', 'Affective', 'Affective', 'Affective', 'Affective', 'Affective'),
    Mediatingvariables = c('Democracy', 'Freedom', 'Equality',
                           'Democracy', 'Freedom', 'Equality',
                           'Democracy', 'Freedom', 'Equality',
                           'Democracy', 'Freedom', 'Equality'),
    Indirecteffect = c(0.006, -0.000, -0.001, 0.000, -0.002, -0.001, 0.001, 0.000, 0.009, 0.000, 0.004, 0.008),
    MCSE= c(0.001, 0.000, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.002, 0.000, 0.001, 0.001),
    MCLLCI = c(0.004, -0.001, -0.002, -0.001, -0.003, -0.002, -0.002, -0.002, 0.006, -0.000, 0.002, 0.006),
    MCULCI = c(0.008, 0.001, 0.000, 0.001, -0.001, 0.000, 0.004, 0.002, 0.012, 0.000, 0.007, 0.011))

colnames(table5data) <- c('Explanatory variables', 
                          'Dependent variables', 
                          'Mediating variables', 
                          'Indirect effect', 
                          'MC S.E.', 
                          'MC LLCI', 
                          'MC ULCI')

knitr::kable(table5data, caption='Summary of indirect effect results', align = 'c') |> 
    kable_styling(latex_options = c('scale_down', 'hold_position'), full_width = FALSE, font_size = 8) |> 
    collapse_rows(columns = 1:2, valign = 'middle') 

# Table A6
models11 <- list(
    'Values' = model16,
    'Political values' = model17,
    'Values' = model18,
    'Political values' = model19,
    'National interest perception' = model20
)

modelsummary(models11,
             title = 'Regression results (Dependent variable is cognitive dimension)',
             output = 'gt',
             voc = 'robust',
             statistic = '({p.value})',
             stars = c('***' = .01, '**' = .05, '*' = .1),
             coef_omit = 'Intercept',
             coef_map = cm,
             gof_map = c('nobs', 'r2.marginal', 'r2.conditional', 'aic','bic','rmse'),
             notes = 'Note: p-Values computed using robust standard errors are in parentheses.'
) |>
    opt_stylize() |> 
    tab_row_group(
        label = md('*Control variables*'),
        rows = 15:26
    ) |> 
    tab_row_group(
        label = md('*Explanatory variables*'),
        rows = 1:14
    ) |> 
    tab_options(table.font.size = px(10),
                data_row.padding = px(2),
                table.width = pct(103) ) |> 
    opt_vertical_padding(scale = 0.25) |> 
    opt_horizontal_padding(scale = 0.4)

# Table A7
models12 <- list(
    'Values' = model11,
    'Political values' = model12,
    'Values' = model13,
    'Political values' = model14,
    'National interest perception' = model15
)

modelsummary(models12,
             title = 'Regression results (Dependent variable is affective dimension)',
             output = 'gt',
             voc = 'robust',
             statistic = '({p.value})',
             stars = c('***' = .01, '**' = .05, '*' = .1),
             coef_omit = 'Intercept',
             coef_map = cm,
             gof_map = c('nobs', 'r2.marginal', 'r2.conditional', 'aic', 'bic', 'rmse'),
             notes = 'Note: p-Values computed using robust standard errors are in parentheses.'
) |>
    opt_stylize() |> 
    tab_row_group(
        label = md('*Control variables*'),
        rows = 15:26
    ) |> 
    tab_row_group(
        label = md('*Explanatory variables*'),
        rows = 1:14
    ) |> 
    tab_options(table.font.size = px(10),
                data_row.padding = px(2),
                table.width = pct(103) ) |> 
    opt_vertical_padding(scale = 0.25) |> 
    opt_horizontal_padding(scale = 0.4)

# ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
# CREATE FIGURES ---------------------------------------------------------------
# ______________________________________________________________________________

# Figure A1
labels1 <- c('1' ='Japan',
             '3' ='South Korea',
             '5' ='Mongolia',
             '6' ='Philippines',
             '8'='Thailand',
             '9'='Indonesia',
             '10'='Singapore',
             '11'='Vietnam',
             '13'='Malaysia',
             '14'='Myanmar',
             '15'='Australia',
             '18'='India')

ggplot(data=data2, aes(x=cni)) + 
    geom_density() + 
    facet_wrap( ~ country, scales = 'fixed', labeller = labeller(country=labels1))+
    theme_minimal()+ 
    labs(caption = 'Data source: The Asian Barometer Survey')+
    theme(plot.title=element_text(face='bold.italic', 
                                  color='black', 
                                  size=18,  
                                  vjust=0.5))+
    xlab('')+
    ylab('Density')+
    theme(axis.title.x=element_text(size=15),
          axis.text.x = element_text(angle = 90, hjust = 0.1, vjust = 0.5, size = 8),
          axis.title.y =element_text(size=15),
          axis.text.y = element_text(size = 10))+  
    theme(strip.background = element_blank(),
          strip.text = element_text(color = 'black',
                                    size = 10)) + 
    scale_x_continuous(breaks=seq(1, 6, 5), labels=c('Very negative','Very positive'))

# Figure A2
p1 <- dwplot(
    list(model6, model1),
    vline = geom_vline(
        xintercept = 0,
        colour = 'green',
        linetype = 4
    ),
    dot_args = list(aes(shape = model)),
    whisker_args = list(aes(linetype = model)),
    vars_order = c('v1', 'v2')
) |>  
    relabel_predictors(
        c(
            'v1' = 'SS values',
            'v2' = 'OC values'
        )
    ) +
    theme_bw(base_size = 11.5) + xlab('Coefficients w/o national interest perception variables') + ylab('') +
    scale_color_startrek(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    scale_shape_discrete(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    guides(
        shape = guide_legend('Dependent variable'),
        colour = guide_legend('Dependent variable')
    )+
    theme(legend.position = 'none')+
    theme(axis.text.y = element_text(size = 14))

p2 <- dwplot(
    list(model3, model8),
    vline = geom_vline(
        xintercept = 0,
        colour = 'green',
        linetype = 4
    ),
    dot_args = list(aes(shape = model)),
    whisker_args = list(aes(linetype = model)),
    vars_order = c('v1', 'v2')
) + 
    theme_bw(base_size = 11.5) + xlab('Coefficients w/ national interest perception variables') + ylab('') +
    theme(axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
    scale_color_startrek(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    scale_shape_discrete(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    guides(
        shape = guide_legend('Dependent variable'),
        colour = guide_legend('Dependent variable')
    )

Rmisc::multiplot(p1, p2, layout = matrix(c(1,2), nrow=1, byrow=TRUE))

# Figure A3
p3 <- dwplot(
    list(model7, model2),
    vline = geom_vline(
        xintercept = 0,
        colour = 'green',
        linetype = 4
    ),
    dot_args = list(aes(shape = model)),
    whisker_args = list(aes(linetype = model)),
    vars_order = c('pv1', 'pv2', 'pv3')
)  |>  
    relabel_predictors(
        c(
            'pv1' = 'Democracy',
            'pv2' = 'Freedom',
            'pv3' = 'Equality'
        )
    ) +
    theme_bw(base_size = 11.5) + xlab('Coefficients w/o national interest perception variables') + ylab('') +
    scale_color_startrek(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    scale_shape_discrete(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    guides(
        shape = guide_legend('Dependent variable'),
        colour = guide_legend('Dependent variable')
    )+
    theme(legend.position = 'none')+
    theme(axis.text.y = element_text(size = 14))

p4 <- dwplot(
    list(model4, model9),
    vline = geom_vline(
        xintercept = 0,
        colour = 'green',
        linetype = 4
    ),
    dot_args = list(aes(shape = model)),
    whisker_args = list(aes(linetype = model)),
    vars_order = c('pv1', 'pv2', 'pv3')
) + 
    theme_bw(base_size = 11.5) + xlab('Coefficients w/ national interest perception variables') + ylab('') +
    theme(axis.text.y = element_blank(), axis.ticks.y = element_blank()) +
    scale_color_startrek(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    scale_shape_discrete(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    guides(
        shape = guide_legend('Dependent variable'),
        colour = guide_legend('Dependent variable')
    )

Rmisc::multiplot(p3, p4, layout = matrix(c(1,2), nrow=1, byrow=TRUE))

# Figure A4 (See the result in # Calculate the mediating effect)
nodes1 <- data.frame(
    name = c('SS values', 'Democracy', 'Freedom', 'Equality', 'Cognitive'),
    x = c(1, 2.5, 2.5, 2.5, 4),          
    y = c(2, 3, 2, 1, 2)                  
)

edges1 <- data.frame(
    x_start = c(1, 1, 1, 2.5, 2.5, 2.5),  
    y_start = c(2, 2, 2, 3, 2, 1),        
    x_end = c(2.5, 2.5, 2.5, 4, 4, 4),   
    y_end = c(3, 2, 1, 2, 2, 2),         
    label = c('0.077***', '-0.002', '0.076***', '0.081***', '0.037***', '-0.014')  
)

me_plot_1 <- ggplot() +
    geom_segment(data = edges1, aes(x = x_start, y = y_start, xend = x_end, yend = y_end),
                 arrow = arrow(length = unit(0.2, 'cm')), size = 0.5, color = zhucao) +
    geom_text(data = edges1, aes(x = (x_start + x_end) / 2, y = (y_start + y_end) / 2 + 0.1, label = label), 
              size = 5, color = zhucao) +
    geom_point(data = nodes1, aes(x = x, y = y), size = 3, color = qingquetoudai) +
    geom_text(data = nodes1, aes(x = x, y = y, label = name), size = 4.5, vjust = 1.5, color = tushoulan) +
    theme_minimal() +
    xlim(0, 5) + ylim(0, 4) +
    theme(
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid = element_blank()
    )

nodes2 <- data.frame(
    name = c('OC values', 'Democracy', 'Freedom', 'Equality', 'Cognitive'),
    x = c(1, 2.5, 2.5, 2.5, 4),          
    y = c(2, 3, 2, 1, 2)                  
)

edges2 <- data.frame(
    x_start = c(1, 1, 1, 2.5, 2.5, 2.5),  
    y_start = c(2, 2, 2, 3, 2, 1),        
    x_end = c(2.5, 2.5, 2.5, 4, 4, 4),   
    y_end = c(3, 2, 1, 2, 2, 2),         
    label = c('0.001', '-0.053***', '0.077***', '0.081***', '0.037***', '-0.012')  
)

me_plot_2 <- ggplot() +
    geom_segment(data = edges2, aes(x = x_start, y = y_start, xend = x_end, yend = y_end),
                 arrow = arrow(length = unit(0.2, 'cm')), size = 0.5, color = zhucao) +
    geom_text(data = edges2, aes(x = (x_start + x_end) / 2, y = (y_start + y_end) / 2 + 0.1, label = label), 
              size = 5, color = zhucao) +
    geom_point(data = nodes2, aes(x = x, y = y), size = 3, color = qingquetoudai) +
    geom_text(data = nodes2, aes(x = x, y = y, label = name), size = 4.5, vjust = 1.5, color = tushoulan) +
    theme_minimal() +
    xlim(0, 5) + ylim(0, 4) +
    theme(
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid = element_blank()
    )

grid.arrange(me_plot_1, me_plot_2, ncol = 1)

# Figure A5  (See the result in # Calculate the mediating effect)
nodes3 <- data.frame(
    name = c('SS values', 'Democracy', 'Freedom', 'Equality', 'Affective'),
    x = c(1, 2.5, 2.5, 2.5, 4),          
    y = c(2, 3, 2, 1, 2)                  
)

edges3 <- data.frame(
    x_start = c(1, 1, 1, 2.5, 2.5, 2.5),  
    y_start = c(2, 2, 2, 3, 2, 1),        
    x_end = c(2.5, 2.5, 2.5, 4, 4, 4),   
    y_end = c(3, 2, 1, 2, 2, 2),         
    label = c('0.078***', '-0.002', '0.074***', '0.015', '-0.088***', '0.116***')  
)

me_plot_3 <- ggplot() +
    geom_segment(data = edges3, aes(x = x_start, y = y_start, xend = x_end, yend = y_end),
                 arrow = arrow(length = unit(0.2, 'cm')), size = 0.5, color = zhucao) +
    geom_text(data = edges3, aes(x = (x_start + x_end) / 2, y = (y_start + y_end) / 2 + 0.1, label = label), 
              size = 5, color = zhucao) +
    geom_point(data = nodes3, aes(x = x, y = y), size = 3, color = qingquetoudai) +
    geom_text(data = nodes3, aes(x = x, y = y, label = name), size = 4.5, vjust = 1.5, color = tushoulan) +
    theme_minimal() +
    xlim(0, 5) + ylim(0, 4) +
    theme(
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid = element_blank()
    )

nodes4 <- data.frame(
    name = c('OC values', 'Democracy', 'Freedom', 'Equality', 'Affective'),
    x = c(1, 2.5, 2.5, 2.5, 4),          
    y = c(2, 3, 2, 1, 2)                  
)

edges4 <- data.frame(
    x_start = c(1, 1, 1, 2.5, 2.5, 2.5),  
    y_start = c(2, 2, 2, 3, 2, 1),        
    x_end = c(2.5, 2.5, 2.5, 4, 4, 4),   
    y_end = c(3, 2, 1, 2, 2, 2),         
    label = c('0.001', '-0.051***', '0.074***', '0.015', '-0.085***', '0.113***')  
)

me_plot_4 <- ggplot() +
    geom_segment(data = edges4, aes(x = x_start, y = y_start, xend = x_end, yend = y_end),
                 arrow = arrow(length = unit(0.2, 'cm')), size = 0.5, color = zhucao) +
    geom_text(data = edges4, aes(x = (x_start + x_end) / 2, y = (y_start + y_end) / 2 + 0.1, label = label), 
              size = 5, color = zhucao) +
    geom_point(data = nodes4, aes(x = x, y = y), size = 3, color = qingquetoudai) +
    geom_text(data = nodes4, aes(x = x, y = y, label = name), size = 4.5, vjust = 1.5, color = tushoulan) +
    theme_minimal() +
    xlim(0, 5) + ylim(0, 4) +
    theme(
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.grid = element_blank()
    )

grid.arrange(me_plot_3, me_plot_4, ncol = 1)

# Figure A6
dwplot(
    list(model10, model5),
    vline = geom_vline(
        xintercept = 0,
        colour = 'green',
        linetype = 4
    ),
    dot_args = list(aes(shape = model)),
    whisker_args = list(aes(linetype = model)),
    vars_order = c('asian', 'world')
) |>  
    relabel_predictors(
        c(
            'asian' = 'Asian',
            'world' = 'Global'
        )
    )+ 
    theme_bw(base_size = 11.5) + xlab('Coefficients of national interest perception variables') + ylab('') +
    scale_color_startrek(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    scale_shape_discrete(
        name = 'Dependent variable',
        labels = c('Cognitive', 'Affective')
    ) +
    guides(
        shape = guide_legend('Dependent variable'),
        colour = guide_legend('Dependent variable')
    )+
    theme(axis.text.y = element_text(size = 12))
